package com.oppo.action;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.oppo.bean.CarMaxBean;
import com.oppo.service.impl.FindCarService;
import com.oppo.tools.MyTools;

@WebServlet("/CarAction")
public class CarAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void service(HttpServletRequest request, HttpServletResponse response) {
		try {
			request.setCharacterEncoding("utf-8");// 设置接收编码类型
			response.setCharacterEncoding("utf-8");// 设置发送编码数据类型
			CarMaxBean one = new CarMaxBean();
			String user_id = request.getSession().getAttribute("user_id").toString();// 将从客户端发送的用户名id转化为字符串
			one.setUser_id(new Long(user_id));// 将接收的id值传给bean
			
			List<CarMaxBean> list = MyTools.getNewInstance(FindCarService.class).jasionQuery(one);
			String strJson = JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd");// 借用第三方工具将list集合转换为json字符串
			PrintWriter JOIN = response.getWriter();//响应客户端的请求
			System.out.println(list);
			JOIN.write(strJson);//将字符串发送给客户端
			JOIN.flush();
			JOIN.close();

		} catch (Exception e) {
			System.out.println("用户信息接收发送错误");
			e.printStackTrace();
		}
	}

}
